<html>
<head>
<meta charset="UTF-8">
<META HTTP-EQUIV="pragma" CONTENT="no-cache"> 
<META HTTP-EQUIV="Cache-Control" CONTENT= "no-cache, must-revalidate"> 
<META HTTP-EQUIV="expires" CONTENT= "Wed, 26 Feb 1997 08:21:57 GMT"> 
<link rel="stylesheet" href="css/jquery.dialogbox.css">
<link rel="stylesheet" href="jquery/easyui/themes/default/easyui.css">
<link rel="stylesheet" href="jquery/easyui/themes/icon.css">
</head>
<body>
	<div style="margin:20px 0 10px 0;text-align: center;">
        <a id="addpanel" href="javascript:void(0)" class="easyui-linkbutton" onclick="ywdList.addPanelTemp('')">增加模版</a>
        <a id="saveorderlist" href="javascript:void(0)" class="easyui-linkbutton" onclick="ywdList.saveorderlist()">保存数据</a>
	</div>
    <div id="ywd_panel" class="easyui-accordion" style="width:100%;height:auto;">
        <!-- <div title="业务单No:1" data-options="tools:[{
                iconCls:'icon-cancel',
                handler:function(){
                	ywdList.removePanelTemp('业务单No:1');
                }
            }],collapsed:false,collapsible:false" style="padding:10px;">
           	 <iframe id="id_1" title="业务单No:1" name="left" frameBorder="0" scrolling="yes" src="index_x_ywd.html" width="100%"></iframe>
        </div> -->
    </div>
<script src="https://upload.shinehao.com.cn/20180816150739jquery-1.8.3.min.js"></script>
<script src="https://upload.shinehao.com.cn/20180816145716jquery.easyui.min.js"></script>
<script src="https://upload.shinehao.com.cn/20180816151727easyui-lang-zh_CN.js"></script>
<script src="js/Util.js"></script>
<script src="https://upload.shinehao.com.cn/20180816151628jquery.dialogBox.js"></script>
<script src="js/base.js"></script>
<script>
var ywdList={
	/*iframe id 下标*/	
	id_index:0,
	orderNos:'',
	orderNos_index:0,
	intval_intvalOrderNo:'',
	//初始化
	init:function(){
		var order_p_buss_no = getQueryString("order_p_buss_no");
		if(order_p_buss_no!=null){
			ywdList.getOrderNoByBussNo(order_p_buss_no);
		}
	},
	/* 通过业务单获取订单编号 List */
	getOrderNoByBussNo:function(order_p_buss_no){
		//获取订单号list
		 $.ajax({
             type: 'POST',
             url: serverUrl+"/createOrder/getOrderNoByBussNo",
             data: {"order_p_buss_no":order_p_buss_no},
             success: function(data){
            	 ywdList.orderNos = data.data;
            	 localStorage.setItem("template_next",0);
            	 //遍历订单号
            	 $.messager.progress({title:'请等待',msg:'<span style="color:green">业务订单载入中...</span>'});
            	 ywdList.intval_intvalOrderNo=setInterval(() => {
            		 ywdList.intvalOrderNo();
				}, 500);
             }
         });
	},
	intvalOrderNo:function(){
		if(localStorage.getItem("template_next")==1||ywdList.orderNos_index==0){
			localStorage.setItem("template_next",0);
			var order_no = ywdList.orderNos[ywdList.orderNos_index].order_p_order_no;
			//通过订单号获取模版
			$.ajax({
	          type: 'POST',
	          url: serverUrl+"/createOrder/getTemplateInfoByOrderNo",
	          data: {"order_no":order_no},
	          success: function(data){
	        	  if(data.data==null){
	              	alert("抱歉,订单编号["+order_no+"]查找不到模版");
	              	return;
	              }
	        	  localStorage.setItem("temp_info_select",data.data.temp_info);
	              localStorage.setItem("temp_info_table_source_arr",data.data.table_source_arr);
	              localStorage.setItem("temp_info_table_source_arr_str",data.data.table_source_arr_str);
	              localStorage.setItem("table_source_line_total",data.data.table_source_line_total);
	              localStorage.setItem("temp_info_table_source_arr_for_two",data.data.table_source_arr_for_two);
	              localStorage.setItem("temp_info_table_source_arr_str_for_two",data.data.table_source_arr_str_for_two);
	              localStorage.setItem("table_source_line_total_for_two",data.data.table_source_line_total_for_two);
	              localStorage.setItem("template_id",data.data.id);
	           		//添加panel 设置iframe src
	  			  ywdList.addPanelTemp("template.html?order_no="+order_no);
	        }});
			ywdList.orderNos_index++;
			if(ywdList.orderNos_index==ywdList.orderNos.length){
				clearInterval(ywdList.intval_intvalOrderNo);
		        $.messager.progress("close");
				return;
			}
		}
	},
	/*增加模版*/
	addPanelTemp:function(url){
		if(url==''){
			url="index_x_ywd.html";
		}
		this.id_index++;
		var id = ywdList.id_index;
		$('#ywd_panel').accordion('add',{
            title:'业务单No:'+id,
            tools:[{
                iconCls:'icon-cancel',
                handler:function(){
                	ywdList.removePanelTemp('业务单No:'+id);
                }
            }],
            collapsed:false,
            collapsible:false,
            content:'<iframe id="id_'+id+'" title="业务单No:'+id+'" name="left" frameBorder="0" scrolling="yes" src="'+url+'" width="100%"></iframe>'
        });
	},
	/*移除模块*/
	removePanelTemp:function(title){
		$('#ywd_panel').accordion('remove',title);
	},
	/*匹配iframe*/
	getFrameId(f){
		var frames = document.getElementsByTagName("iframe"); //获取父页面所有iframe
		for(i=0;i<frames.length;i++){ //遍历，匹配时弹出id
			if(frames[i].contentWindow == f){
				return(frames[i].id)
			}
		}
	},
	/* 保存所有业务单 */
	saveorderlist:function(){
		var frames = document.getElementsByTagName("iframe"); //获取父页面所有iframe
		var bool = true;
		for(i=0;i<frames.length;i++){ //遍历，匹配时弹出id
			if($(frames[i]).contents().find("[name='order_p_buss_no']").length>0){
				if($(frames[i]).contents().find("[name='order_p_buss_no']").val().trim().length<1){
					alert(frames[i].title+" 业务单号组件必填，请补充再保存");
					bool=false;
				}				
			}else{
				alert(frames[i].title+" 缺少业务单号组件，请补充再保存");
				bool=false;
			}
		}
		if(bool){
			ywdList.saveorderlistAjax();
		}
	},
	/* 保存所有业务单 ajax */
	saveorderlistAjax:function(){
		var frames = document.getElementsByTagName("iframe"); //获取父页面所有iframe
		for(i=0;i<frames.length;i++){ //遍历，匹配时弹出id
			frames[i].contentWindow.basic_index.saveAsTemp();
		}
	}
}
ywdList.init();
</script>
</body>
</html>